package org.huangrui.javase.thread;

/**
 * 有序执行
 * @Author hr
 * @Create 2025-11-08 13:27
 **/
public class T02OrderedExecution1 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("Thread 1 is running");
        });

        Thread t2 = new Thread(() -> {
            try {
                t1.join(); // 等待t1执行完毕
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread 2 is running");
        });

        Thread t3 = new Thread(() -> {
            try {
                t2.join(); // 等待t2执行完毕
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread 3 is running");
        });

        t1.start();
        t2.start();
        t3.start();
    }
}
